<template>
	<view class="container">
		<!-- 顶部用户信息 -->
		<view class="user-info">
			<view class="avatar-container" @click="handleUserInfo">
				<uni-id-pages-avatar v-if="userInfo.avatar_file && userInfo.avatar_file.url" width="80rpx" height="80rpx" style="pointer-events: none;"></uni-id-pages-avatar>
				<image class="avatar" v-else src="/static/images/avatar.png" mode="aspectFill"></image>
			</view>
			<text class="username">{{userInfo.nickname || '未登录'}}</text>
			<view class="task-button" @click="logout" v-if="hasLogin">
				<text class="task-icon">●</text>
				<text class="task-text">退出登录</text>
			</view>
		</view>
		
		<!-- 中间数据统计 -->
		<view class="stats-card">
			<view class="stats-row">
				<view class="stat-item">
					<text class="stat-label">答题卡</text>
					<text class="stat-value">15</text>
				</view>
				<view class="stat-item">
					<text class="stat-label">积分</text>
					<text class="stat-value">230</text>
				</view>
			</view>
			<view class="invite-info">
				<text class="invite-text">已邀请 <text class="highlight">3</text> 人，获得 <text class="highlight">6</text> 张答题卡</text>
			</view>
			<button class="get-card-button" @click="navigateToTask">
				<text class="button-icon">+</text>
				<text class="button-text">获取答题卡</text>
			</button>
		</view>
		
		<!-- 开始答题按钮 -->
		<view class="start-container">
			<view class="start-button" @click="startQuiz">
				<view class="start-content">
					<text class="start-icon">▶</text>
					<text class="start-text">开始答题</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script setup>
import { computed, ref } from 'vue';
import {
store,
mutations
} from '@/uni_modules/uni-id-pages/common/store.js';
import pagesJson from '@/pages.json';
import { routerTo, showModal } from '../../utils/common';

const userInfo = computed(()=>store.userInfo);
const hasLogin = computed(()=>store.hasLogin);

const stats = ref({
  cards: 15,
  points: 230,
  invites: 3,
  cardsFromInvites: 6
});

const logout = async () => {
	let feedback = await showModal({content:"是否确认退出登录？"});
	if(feedback == "confirm") mutations.logout();
	
};

// 登录或者个人中心
const handleUserInfo = ()=>{
	if(hasLogin.value){
		routerTo(`/uni_modules/uni-id-pages/pages/userinfo/userinfo`);
	}else{
		routerTo(`/${pagesJson.uniIdRouter.loginPage}`);
	}
	
}

const navigateToTask = () => {
  uni.switchTab({
    url: '/pages/task/task'
  });
};

const startQuiz = () => {
  uni.switchTab({
    url: '/pages/quiz/quiz'
  });
};
</script>


<style>
	.container {
		display: flex;
		flex-direction: column;
		background-image: linear-gradient(135deg, #67b3ff 0%, #ffffff 100%);
		min-height: 100vh;
		padding: 20rpx;
	}
	
	/* 顶部用户信息 */
	.user-info {
		display: flex;
		align-items: center;
		padding: 20rpx;
		margin-top: 20rpx;
	}
	
	.avatar-container {
		width: 80rpx;
		height: 80rpx;
		border-radius: 50%;
		overflow: hidden;
		border: 4rpx solid #a7c9ff;
		background-color: #fff;
	}
	
	.avatar {
		width: 100%;
		height: 100%;
	}
	
	.username {
		margin-left: 20rpx;
		font-size: 32rpx;
		font-weight: 500;
		color: #333;
	}
	
	.task-button {
		margin-left: auto;
		background-color: #3b82f6;
		color: white;
		border-radius: 40rpx;
		padding: 10rpx 20rpx;
		display: flex;
		align-items: center;
		font-size: 26rpx;
		box-shadow: 0 4rpx 10rpx rgba(0, 0, 0, 0.1);
	}
	
	.task-icon {
		margin-right: 10rpx;
		font-size: 20rpx;
	}
	
	/* 中间数据统计 */
	.stats-card {
		margin: 20rpx;
		background-color: white;
		border-radius: 20rpx;
		padding: 30rpx;
		box-shadow: 0 4rpx 15rpx rgba(0, 0, 0, 0.1);
	}
	
	.stats-row {
		display: flex;
		justify-content: space-between;
		margin-bottom: 20rpx;
	}
	
	.stat-item {
		display: flex;
		flex-direction: column;
		align-items: center;
	}
	
	.stat-label {
		font-size: 24rpx;
		color: #666;
	}
	
	.stat-value {
		font-size: 40rpx;
		font-weight: bold;
		color: #3b82f6;
	}
	
	.invite-info {
		background-color: #eef5ff;
		border-radius: 10rpx;
		padding: 20rpx;
		text-align: center;
		font-size: 24rpx;
		color: #666;
	}
	
	.highlight {
		color: #3b82f6;
		font-weight: 500;
	}
	
	.get-card-button {
		margin-top: 20rpx;
		background-image: linear-gradient(135deg, #3b82f6 0%, #1e40af 100%);
		color: white;
		border-radius: 10rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 28rpx;
		padding: 20rpx 0;
		font-weight: 500;
	}
	
	.button-icon {
		margin-right: 10rpx;
	}
	
	/* 开始答题按钮 */
	.start-container {
		display: flex;
		justify-content: center;
		margin-top: 80rpx;
		margin-bottom: 120rpx;
	}
	
	.start-button {
		width: 200rpx;
		height: 200rpx;
		border-radius: 100rpx;
		background-image: linear-gradient(135deg, #3b82f6 0%, #1e40af 100%);
		display: flex;
		align-items: center;
		justify-content: center;
		box-shadow: 0 8rpx 20rpx rgba(0, 0, 0, 0.2);
	}
	
	.start-content {
		display: flex;
		flex-direction: column;
		align-items: center;
	}
	
	.start-icon {
		font-size: 50rpx;
		color: white;
		margin-bottom: 10rpx;
	}
	
	.start-text {
		font-size: 32rpx;
		font-weight: bold;
		color: white;
	}
</style> 